package com.study.homework.timer;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TraditionalTimerTest {
	private static int count = 0;
	public static void main(String[] args) {
//		new Timer().schedule(new TimerTask(){
//
//			@Override
//			public void run() {
//				System.out.println("bombing");
//				new Timer().schedule(this, 2000);
//				
//			}}, 2000);
		
//	test1();
	test2();
	}
	private static void test1() {
		class MyTimerTask extends TimerTask{
				
				@Override
				public void run() {
					count = (count+1)%2;
					System.out.println("bombing");
					new Timer().schedule(new MyTimerTask(), 2000+2000*count);
					
				}
			}
				new Timer().schedule(new MyTimerTask(), 2000);
				printTime();
		
	}
	private static void test2() {
		
		new Timer().schedule(new MyTimerTask1(), 2000);
		printTime();
		
	}
		private static void printTime() {
			while(true){
				System.out.println(System.currentTimeMillis()/1000);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
}

class MyTimerTask1 extends TimerTask{
	
	@Override
	public void run() {
		System.out.println("bombing");
		new Timer().schedule(new MyTimerTask2(), 4000);
		
	}
}
class MyTimerTask2 extends TimerTask{
	
	@Override
	public void run() {
		System.out.println("bombing");
		new Timer().schedule(new MyTimerTask1(), 2000);
		
	}
}
